package com.atguigu.gmall.product.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseCategoryView;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api/product")
public class ProductApiController {
    @Autowired
    private ManageService manageService;

    //带有inner的url 表示给内部服务调用的接口
    @GetMapping("inner/getSkuInfo/{skuId}")
    public SkuInfo skuInfo(@PathVariable Long skuId) {
        SkuInfo skuInfo = manageService.getSkuInfo(skuId);
        return skuInfo;

    }

    @GetMapping("inner/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(Long category3Id) {
        BaseCategoryView categoryViewByCategory3Id = manageService.getCategoryViewByCategory3Id(category3Id);
        return categoryViewByCategory3Id;
    }

    @GetMapping("inner/getSkuValueIdsMap/{spuId}")
    public Map getSkuValueIdsMap(@PathVariable Long spuId) {
        return manageService.getSkuValueIdsMap(spuId);
    }

    /**
     * 获取首页列表
     *
     * @return
     */
    @GetMapping("getBaseCategoryList")
    public Result getBaseCategoryList() {

        List<JSONObject> baseCategoryList = manageService.getBaseCategoryList();
        return Result.ok(baseCategoryList);
    }

    @GetMapping("inner/getTrademark/{tmId}")
    public BaseTrademark getBaseTradeMark(@PathVariable Long tmId) {

        return manageService.getTrademarkByTmId(tmId);

    }
    /**
     *  根据skuid获取平台属性平台属性值
     */
    @GetMapping("inner/getAttrList/{skuId}")
    public List<BaseAttrInfo> getAttrList(@PathVariable Long skuId){
        return  manageService.getAttrList(skuId);
    }

}
